<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<style>
.all_list select {
	width: 120px;
}
</style>
<div class="r_location">
	<i class="r_txtico"></i> 内容管理&gt; 活动管理 
</div>
<div class="m-t10">
	
	<div class="clearfix table_fn">
			<span class="l">微信活动管理数据列表</span> <span class="r"
				style="_margin-top: 5px;"> <a href="#" title="" class="add_ico" onclick="addActivity()" id="add_term">新增</a>
			</span>
	</div>
	
	<table id="activity_table">
	</table>
	<div id="pgtoolbar"></div>
</div>
<script>
   function addActivity(){
		to_page('/cms/activity/add/page');
   }

	function modify(id){
		to_page('/cms/activity/modify/page?id='+id);
	}
	
	function del(id){
		art.dialog({
			title : '删除活动',
			lock : true,
			content : '确认删除活动?',
			width : '200px',
		    cancelVal: '关闭',
		    cancel: true,
			ok : function () {
				$.post("cms/activity/delete", {id:id}, function(data) {
					if(data.code!="01"){
						$("#activity_table").jqGrid("setGridParam", {
							datatype : "json"
						}).trigger("reloadGrid", [ {
							page : 1
						} ]);
					}
				});
			}
		});
	}
 
 
	$(function() {
		
		$.jgrid.ajaxOptions.type = 'post';
		$("#activity_table").jqGrid({
			url : "cms/activity/view",
			datatype : "json",
			colModel : [{
				label : '活动编号',
				name : 'activityCode',
				index : 'activityCode',
				width:50
			}, {
				label : '活动名称',
				name : 'activityName',
				index : 'activityName',
				width:80
			}, {
				label : '开始时间',
				name : 'startDate',
				index : 'startDate',
				formatter : to_date_hms,
				width:100
			}, {
				label : '结束时间',
				name : 'endDate',
				index : 'endDate',
				width:100,
				align:'left'
			} ,{
				label : '活动状态',
				name : 'status',
				index : 'status',
				 formatter:function(cell,options,row){
					 if(row.status=='new'){
						 return '新建';
					 }
 					if(row.status=='discarded'){
						 return '已作废';
					 }
 					if(row.status=='pause'){
						 return '暂停';
					 }
					return row.status;
				}, 
				width:50,
				align:'left'
			}, {
				label : '操作',
				name : 'operation',
				index : 'operation',
				width: 50,
				formatter:function(cell,options,row){
					var result = '';
					result = '<a href="#" onclick="modify(\''+row.id+'\')">修改</a>';
					result = result + ' <a href="#" onclick="del(\''+row.id+'\')">删除</a>';
					return result;
				}
			}],
			height : 370,
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			viewrecords : true,
			pager : '#pgtoolbar',
			autowidth : true,
			rownumbers : true,
			jsonReader : {
				root : "data",//当前记录
				page : "index",
				records : "totalRecord",//总记录数
				total : 'total',//总页数
				id : 'data.id',
				repeatitems : false
			}
			
		});
		function serialize_list(cell,options,row){
			var result = new Array();
			for(var i=0;i<cell.length;i++){
				result[i] = cell[i].name;
			}
			return result.join(';');
		};
	

		$("#query").click(function() {
			var param = {};			
			var paramArray = $('#qForm').serializeArray();
			for (var i in paramArray) {
				param[paramArray[i].name] = paramArray[i].value;
			}
			var postData = $("#activity_table").jqGrid("getGridParam","postData");
			$.extend(postData, param);
			$("#activity_table").jqGrid("setGridParam", {
				datatype : "json"
			}).trigger("reloadGrid", [ {
				page : 1
			} ]);
		});
	});
</script>